package com.lovo.ssc.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lovo.dto.PendingCommodityDto;
import com.lovo.ssc.entity.SysDeliver;
import com.lovo.ssc.entity.SysGoods2;
import com.lovo.ssc.entity.SysStore;
import com.lovo.ssc.service.ISysDeliverService;
import com.lovo.ssc.service.ISysGoods2Service;
import com.lovo.ssc.service.ISysStoreService;
import com.lovo.sscsys.dto.SysGoodsTotalMQDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 总库存商品表 前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-07
 */
@RestController
@RequestMapping("/sysgoods2")
@Api(tags = "商品总库存控制器-张海军-002")
public class SysGoods2Controller {
    @Autowired
    ISysGoods2Service service;
    @Autowired
    ISysDeliverService sysDeliverService;
    @Autowired
    ISysStoreService sysStoreService;

    /**
     * 1.查询全部商品总库存
     *
     * @return
     */

    @ApiOperation(value = "查询全部商品总库存")
    @GetMapping("findAll")
    public List<SysGoods2> findAll() {
        List<SysGoods2> list=   service.list();
        return list;
    }

        /**
     * 1.1 查询未定价的商品
     *2
     * @return
     */

    @ApiOperation(value = "查询未定价的商品")
    @GetMapping("findByOriginal")
    public List<PendingCommodityDto> findByOriginal() {
        QueryWrapper qw=new QueryWrapper();
        qw.eq("state","未定价");
        List<SysGoods2> list=   service.list(qw);
        System.out.println("----测试----");
        System.out.println(list);
        List<PendingCommodityDto> list1   =new ArrayList<>();
        for (SysGoods2 sysGoods2 : list) {
            PendingCommodityDto dto=new PendingCommodityDto();
            dto.setCommodityCode(sysGoods2.getCode());
            dto.setCommodityname(sysGoods2.getGoodsName());
            dto.setType(sysGoods2.getType());
            dto.setNorms(sysGoods2.getSpecs());
            dto.setPrice(sysGoods2.getAveInPrice());
            dto.setNumber(sysGoods2.getStockNum());
            list1.add(dto);
        }
        return list1;
    }

    /**
     * 2.查询全部入库明细
     *
     * @return
     */

    @ApiOperation(value = "查询全部入库明细")
    @GetMapping("findAllInDetail")
    public List<SysStore> findAllInDetail() {
        List<SysStore> list=   sysStoreService.list();
        return list;
    }

    /**
     * 3.查询全部上架出库明细
     *
     * @return
     */

    @ApiOperation(value = "查询全部上架出库明细")
    @GetMapping("findAllOutDetail")
    public List<SysDeliver> findAllOutDetail() {
        List<SysDeliver> list=   sysDeliverService.list();
        return list;
    }
    /**
     * 4.测试定价操作
     *
     * @return
     */

    @ApiOperation(value = "测试定价操作")
    @GetMapping("TestUpdatePrice")
    public void TestUpdatePrice(String goodsCode, Float newPrice) {
        service.updatePrice(goodsCode,newPrice);

    }




}
